<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('活动列表')" />
</head>
<style>
    .file {
        position: relative;
        display: inline-block;
        background: #D0EEFF;
        border: 1px solid #99D3F5;
        border-radius: 4px;
        padding: 4px 12px;
        overflow: hidden;
        color: #1E88C7;
        text-decoration: none;
        text-indent: 0;
        line-height: 20px;
    }
    .file input {
        position: absolute;
        font-size: 100px;
        right: 0;
        top: 0;
        opacity: 0;
    }
    .file:hover {
        background: #AADFFD;
        border-color: #78C3F3;
        color: #004974;
        text-decoration: none;
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="activity-form">
                <div class="select-list">
                    <ul>
                        <li>
                            活动标题：<input type="text" name="activityTitle"/>
                        </li>
                        <li>
                            操作人员：<input type="text" name="createBy"/>
                        </li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="system:activity:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editFull()" shiro:hasPermission="system:activity:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:activity:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
<!--            <a class="btn btn-danger multiple disabled" id="uptea"  shiro:hasPermission="system:activity:remove">-->
<!--                <i class="fa fa-remove"></i> 上传视频-->
<!--            </a>-->
            <!--				<button  type="button" class="btn btn-primary">上传</button>-->
            <!--				<a href="javascript:;" class="file" style="-->
            <!--						position: relative;-->
            <!--						top: 32px;-->
            <!--						display: inline-block;-->
            <!--						background: #D0EEFF;-->
            <!--						border: 1px solid #99D3F5;-->
            <!--						border-radius: 4px;-->
            <!--						padding: 4px 12px;-->
            <!--						overflow: hidden;-->
            <!--						color: #1E88C7;-->
            <!--						text-decoration: none;-->
            <!--						text-indent: 0;-->
            <!--						line-height: 20px;">上传视频-->
            <!--					<input type="file" name="filePath" id="filePath" multiple="multiple" style="-->
            <!--						position: absolute;-->
            <!--						font-size: 100px;-->
            <!--						right: 0;-->
            <!--						top: 0;-->
            <!--						opacity: 0;">-->
            <!--				</a>-->
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
    <form id="upform" enctype='multipart/form-data' style="display:none;">
        <input id="upteainput" name="filePath" class="form-control" type="file">
    </form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:activity:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:activity:remove')}]];
    // var types = [[${@dict.getType('sys_activity_type')}]];
    var datas = [[${@dict.getType('sys_activity_status')}]];
    var prefix = ctx + "system/activity";

    $("#uptea").click(function () {
        $("#upteainput").click();
    });

    //下面是ajax上传文件的代码，此处就不做过多讲解。
    $("#upteainput").change(function () {//如果上传文件的input内容发生了变化
        $val = $("#upteainput").val();
        if ($val != '') {//要上传的文件名不为空
            $data = new FormData($("#upform")[0]);//创建一个formdata对象
            $host = window.location.host;
            $.ajax({
                url: "/common/upload",
                type: "POST",
                data: $data,
                processData: false,
                contentType: false,
                dataType: "json",
                error: function () {
                    alert('上传失败！');
                },
                success: function (data, status) {//如果调用php成功
                    if (data.errno != 0) {
                        if (data.errmsg != '') {
                            alert(data.errmsg);
                        } else {
                            alert("系统错误");
                        }
                    }
                    console.log(data);
                    alert("上传成功!");
                    window.location.reload();
                }
            });
        }
    });

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "活动",
            columns: [{
                checkbox: true
            },
                {
                    field : 'activityId',
                    title : '序号',
                    visible: false
                },
                {
                    field : 'activityTitle',
                    title : '活动标题'
                },
                {
                    field : 'activityViodeo',
                    title : '视频链接'
                },
                {
                    field: 'status',
                    title: '状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field : 'createBy',
                    title : '创建者'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.activityId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.activityId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>